package org.reference.generic.operator;

import org.reference.generic.base.Parameter;

/**
 * 
 */
public class Terminal extends Node {
    /**
     * 
     */
    public interface OnRequestParameterListenner {

        /**
         * @param requestParam 
         * @return
         */
        public abstract Parameter onRequestParameter(Parameter requestParam);

    }
    
    /**
     * 
     */
    public Terminal(Parameter[] parameters) {
    	super(parameters);
    	terminal = true;
    	
    	for (Parameter param : parameters) {
    		if (param.getName().equalsIgnoreCase(Parameter.TYPE_TERM_VALUE)) {
    			typeParam = param;
    			break;
    		}
    	}
    }

    private Parameter typeParam;
    private OnRequestParameterListenner onRequestParamListenner;

    public void setOnRequestParameterListenner(OnRequestParameterListenner listenner) {
    	onRequestParamListenner = listenner;
    }

	@Override
	public double getResult() {
		double value = 0.0d;

		if (onRequestParamListenner != null) {
			Parameter respParam = onRequestParamListenner.onRequestParameter(typeParam);
			value = respParam.getValueToDouble();
		}		
		setResult(value);
		
		return super.getResult();
	}

}